package sc.analysis.aroon;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.VIntWritable;
import org.apache.hadoop.io.Writable;

/**
 * Used to store data between the mapper and the reducer of Aroon.
 * 
 * @author Quentin Rossé
 *
 */
public class AroonData implements Writable{
	
	/**
	 * used to write integers
	 */
	private static VIntWritable vint = new VIntWritable();
	
	/**
	 * Period for this Aroon analysis
	 */
	private int period;
	
	/**
	 * Value of down
	 */
	private int down;
	
	/**
	 * Value of up
	 */
	private int up;
	
	/**
	 * Value of down the previous day
	 */
	private int prevDown;
	
	/**
	 * Value of up the previous day
	 */
	private int prevUp;
	
	
	public AroonData(){}
	
	public AroonData(int period, int down, int up, int pDown, int pUp) {
		this.period = period;
		this.down = down;
		this.up = up;
		this.prevDown = pDown;
		this.prevUp = pUp;
	}

	public int getPeriod() {
		return period;
	}

	public void setPeriod(int period) {
		this.period = period;
	}

	public int getDown() {
		return down;
	}

	public void setDown(int down) {
		this.down = down;
	}

	public int getUp() {
		return up;
	}

	public void setUp(int up) {
		this.up = up;
	}

	public int getPrevDown() {
		return prevDown;
	}

	public void setPrevDown(int prevDown) {
		this.prevDown = prevDown;
	}

	public int getPrevUp() {
		return prevUp;
	}

	public void setPrevUp(int prevUp) {
		this.prevUp = prevUp;
	}
	
	public void setAll(int period, int down, int up, int pDown, int pUp) {
		this.period = period;
		this.down = down;
		this.up = up;
		this.prevDown = pDown;
		this.prevUp = pUp;
	}

	@Override
	public void readFields(DataInput in) throws IOException {
		vint.readFields(in);
		period = vint.get();
		vint.readFields(in);
		down = vint.get();
		vint.readFields(in);
		up = vint.get();
		vint.readFields(in);
		prevDown = vint.get();
		vint.readFields(in);
		prevUp = vint.get();
	}

	@Override
	public void write(DataOutput out) throws IOException {
		vint.set(period);
		vint.write(out);
		vint.set(down);
		vint.write(out);
		vint.set(up);
		vint.write(out);
		vint.set(prevDown);
		vint.write(out);
		vint.set(prevUp);
		vint.write(out);
	}

}
